package com.swn.common.util;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;


/**
 * BaseJunitUtil工具类，其他类可以继承该类，并进行spring框架Junit测试
 * 
 * @author taozhaocai
 * @Date 2016-5-12 下午5:14:00
 * @Note <这里是该类的使用注意事项>
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("/spring.xml")
public class BaseJunitUtil {
	@Autowired
	public DbHelper dbHelper;
	@Autowired
	JdbcTemplate jdbcTemplate;
	
	@Test
	public void testdd() throws Exception {
		Map<String,Object> map = dbHelper.queryForMap("select * from test1 where id =1");
		
		System.out.println(map.get("name"));
		//DbTableUtil.initOracleTable(null);
	}

	@Test
	public void test() {
		List list = jdbcTemplate.queryForList("select * from stu_info");
		System.out.println(list.size());
		//DbTableUtil.initOracleTable(null);
	}
	
	@Test
	public void testMap(){
		Map<String,Object> map = jdbcTemplate.queryForMap("select * from stu_info t1,stu_info2 t2 where t1.id=t2.id ");
		System.out.println(map.get("NAME"));
		
		
	}
	
	@Test
	public void testMap2(){
	try {
		String sql ="UPDATE STU_INFO SET AGE=:age,NAME=:NAME,WEIGHT=:WEIGHT WHERE ID=:ID";
		//Map<String, Object> paramMap = new CaseInsensitiveMap(); 
		Map<String, Object> paramMap = new HashMap(); 
		paramMap.put("ID", 1);
		paramMap.put("age", 1);
		paramMap.put("NAME", 1);
		paramMap.put("WEIGHT", 1);
		
		int k = this.dbHelper.update(sql, paramMap);
		System.out.println(k);
	} catch (Exception e) {
		e.printStackTrace();
	}
		
		
	}
	
	@Test
	public void testMap3(){
	try {
		String sql ="insert into DEMO_STU_INFO (ID, NME, SEX, BIRTH, HEIGHT, WEIGHT, REMARK, ORG_ID, ADDRESS) "+
"values (DEMO_STU_INFO_SEQ.NEXTVAL, '1', 1, '1', 1.00, 1.00, '1', 1, '1')";
		//Map<String, Object> paramMap = new CaseInsensitiveMap(); 
		Map<String, Object> paramMap = new HashMap(); 
		paramMap.put("ID", 1);
		paramMap.put("age", 1);
		paramMap.put("NAME", 1);
		paramMap.put("WEIGHT", 1);
		
		int k = this.dbHelper.update(sql, paramMap);
		System.out.println(k);
	} catch (Exception e) {
		e.printStackTrace();
	}
		
		
	}

	@Test
	public void insertData() {
		long t1 = System.currentTimeMillis();
		dbHelper.update("delete from demo_family");
		dbHelper.update("delete from DEMO_FAMILY_MEMBER");
		for (int i = 1; i <= 150000; i++) {
			try {
				dbHelper.update("insert into demo_family (ID, NAME, ADDRESS, ORG_ID)values ("+i+", '王璐丹"+i+"', '大学路', 370000)");
				dbHelper.update("insert into DEMO_FAMILY_MEMBER (ID, FAMILY_ID, NAME, RELATIONSHIP) values ("+i+", "+i+", '王明飞"+i+"', '父子')");
				System.out.println(i);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		
		for (int i = 150001; i <= 300000; i++) {
			try {
				dbHelper.update("insert into demo_family (ID, NAME, ADDRESS, ORG_ID)values ("+i+", '李秋明"+i+"', '求实路', 370100)");
				dbHelper.update("insert into DEMO_FAMILY_MEMBER (ID, FAMILY_ID, NAME, RELATIONSHIP) values ("+i+", "+i+", '李明飞"+i+"', '父子')");
				System.out.println(i);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		
		for (int i = 300001; i <= 450000; i++) {
			try {
				dbHelper.update("insert into demo_family (ID, NAME, ADDRESS, ORG_ID)values ("+i+", '诸葛东"+i+"', '博学路', 370200)");
				dbHelper.update("insert into DEMO_FAMILY_MEMBER (ID, FAMILY_ID, NAME, RELATIONSHIP) values ("+i+", "+i+", '诸葛明"+i+"', '父子')");
				System.out.println(i);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		
		long t2 = System.currentTimeMillis();
		System.out.println((t2-t1)/1000.00);
	}
	
	
}
